package cn.jhc.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sql.DataSource;

import uuntil.Constants;
import cn.jhc.bean.Song;
import cn.jhc.db.SongDao;


/**
 * Servlet implementation class ListSong
 */
@WebServlet("/listsong.do")
public class ListSong extends HttpServlet {
	private static final long serialVersionUID = 1L;

    public ListSong() {
        super();  
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("appliction/json;charset=utf8");
		DataSource dataSource = (DataSource)request.getServletContext().getAttribute(Constants.H2_DATASOURCE);		
		List<Song> songs=SongDao.findAllsong(dataSource);
		request.setAttribute("songs",songs);	
		request.getRequestDispatcher("songsearch.jsp").forward(request, response);
		
		
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//		response.setContentType("appliction/json;charset=utf8");
//		DataSource dataSource = (DataSource)request.getServletContext().getAttribute(Constants.H2_DATASOURCE);		
//		List<Song> songs=SongDao.findAllsong(dataSource);
//		request.setAttribute("songs",songs);
//		
////		List<Song> songSearch=SongDao.searchSong(dataSource);
////		request.setAttribute("songSearch",songSearch);
//		
//		request.getRequestDispatcher("songsearch.jsp").forward(request, response);
		
	}

}
